package com.job.client.auth.controller;

import com.job.client.common.result.ResponseResult;
import com.job.client.auth.service.AuthService;
import com.job.client.model.auth.pojo.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/api/v1/client/auth")
@Slf4j
@Api(tags = "客户端登录注册接口文档")
public class AuthController {

    @Autowired
    private AuthService authService;
    @PostMapping("/getImgCode")
    @ApiOperation("生成图形验证码")
    public ResponseResult getImgCode(HttpServletResponse response, HttpServletRequest request){
        return authService.getImgCode(response,request);
    }
    @GetMapping("/checkImgCode")
    @ApiOperation("校验图形验证码")
    public ResponseResult checkImgCode(String code, HttpServletRequest request){
        return authService.checkImgCode(code,request);
    }
    @PostMapping("/sendSmsCode")
    @ApiOperation("发送阿里云的短信服务")
    public ResponseResult sendSmsCode(@RequestBody String phone, HttpServletRequest request){
        return authService.sendSmsCode(phone,request);
    }
    @GetMapping("/checkSmsCode")
    @ApiOperation(("检查短信验证码是否正确"))
    public ResponseResult checkSmsCode(@RequestParam String code,@RequestParam String phone, HttpServletRequest request){
        return authService.checkSmsCode(code,phone,request);
    }
    @PostMapping("/register")
    @ApiOperation("注册")
    public ResponseResult Register(@RequestBody User user){
        return authService.register(user);
    }
    @PostMapping("/login")
    @ApiOperation("登录")
    public ResponseResult login(@RequestBody User user){
        return authService.login(user);
    }
    @PostMapping("/logout")
    @ApiOperation("退出")
    public ResponseResult logout(@RequestBody String userId){
        return authService.logout(userId);
    }
    @GetMapping("/getUserInfo")
    @ApiOperation("通过发送请求携带的token获得用户的信息")
    public ResponseResult getUserInfo(HttpServletRequest request){
        return authService.getUserInfo(request);
    }
    @PostMapping("/uploadAvatar")
    @ApiOperation("上传用户头像到minio")
    public ResponseResult uploadAvatar(@RequestParam MultipartFile file,@RequestParam  String Authorization){
        return authService.uploadAvatar(file,Authorization);
    }
    @PostMapping("/updateAvatar")
    @ApiOperation("修改用户头像")
    public ResponseResult updateAvatar(@RequestBody User user){
        return authService.updateAvatar(user);
    }
    @PostMapping("/addDuties")
    @ApiOperation(" 给用户添加职务")
    public ResponseResult addDuties(@RequestBody String duties,HttpServletRequest request){
        return authService.addDuties(duties,request);
    }
    @PostMapping("/addCompany")
    @ApiOperation("给用户添加公司")
    public ResponseResult addCompany(@RequestBody String company,HttpServletRequest request){
        return authService.addCompany(company,request);
    }
    @GetMapping
    @ApiOperation("开放给后台管理系统，通过userId获得用户信息的接口")
    public ResponseResult getUserInfoById(@RequestParam String userId){
        return authService.getUserInfoById(userId);
    }

    @GetMapping("/authentication")
    @ApiOperation("公司认证用户")
    public ResponseResult authentication(
            @RequestParam String companyId,
            @RequestParam String userId,
            @RequestParam String companyName){
        return authService.authentication(companyId,userId,companyName);
    }

    @GetMapping("/get/company")
    @ApiOperation("根据用户id获得用户创建的公司信息")
    public ResponseResult getCompanyByUserId(@RequestParam String userId){
        return authService.getCompanyByUserId(userId);
    }
}
